﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Serie_Counter.General
{
    public delegate void SelectedMoveOptionChanged(AutoMoveOption selectedOption, int checkInterval = 30 );

    public delegate void EnableAutoMoveChanged(bool EnableAutoMove);

    [Serializable]
    public class Settings :ICloneable
    {
        private string serieListSavePath;
        private bool autoStart;
        private bool enableRember;
        private bool closeWithMainForm;
        private int warningDelay;
        // moving options
        private bool enableAutoMove;
        private string rootFolder;
        private int checkInterval;
        private AutoMoveOption selectedMoveOption;
        
        public event SelectedMoveOptionChanged selectedMoveOptionChanged;
        public event EnableAutoMoveChanged enableAutoMoveChanged;

        #region Properties

        public string SerieListSavePath
        {
            get
            {
                return serieListSavePath;
            }
            set
            {
                serieListSavePath = value;
            }
        }

        public bool AutoStart
        {
            get
            {
                return autoStart;
            }
            set
            {
                autoStart = value;
            }
        }

        public bool EnableRember
        {
            get
            {
                return enableRember;
            }
            set
            {
                enableRember = value;
            }
        }

        public bool CloseWithMainForm
        {
            get
            {
                return closeWithMainForm;
            }
            set
            {
                closeWithMainForm = value;
            }
        }

        public int WarningDelay
        {
            get
            {
                return warningDelay;
            }
            set
            {
                warningDelay = value;
            }
        }

        public bool EnableAutoMove
        {
            get
            {
                return enableAutoMove;
            }
            set
            {
                enableAutoMove = value;
                if (enableAutoMove != null) enableAutoMoveChanged(value);
            }
        }

        public string RootFolder
        {
            get
            {
                return rootFolder;
            }
            set
            {
                rootFolder = value;
            }
        }

        public int CheckInterval
        {
            get
            {
                return checkInterval;
            }
            set
            {
                checkInterval = value;
            }
        }

        public AutoMoveOption SelectedMoveOption
        {
            get
            {
                return selectedMoveOption;
            }
            set
            {
                selectedMoveOption = value;
                selectedMoveOptionChanged(value, checkInterval);

            }
        }

        #endregion



        public Settings(string serieListSavePath)
        {
            this.serieListSavePath = serieListSavePath;
        }

        public Settings()
        {
            this.serieListSavePath = "series.xml";
            warningDelay = -1;
        }

        public Settings(Settings settings)
        {
            this.rootFolder = settings.rootFolder;
            this.selectedMoveOption = settings.selectedMoveOption;
            this.warningDelay = settings.warningDelay;
            this.serieListSavePath = settings.serieListSavePath;
            this.enableRember = settings.enableRember;
            this.autoStart = settings.autoStart;
            this.checkInterval = settings.checkInterval;
            this.closeWithMainForm = settings.closeWithMainForm;
            this.enableAutoMove = settings.enableAutoMove;
        }

        public Settings Serialize()
        {
            Settings settings = (Settings)this.Clone();
            settings.selectedMoveOptionChanged = null;
            settings.enableAutoMoveChanged = null;
            return settings;
        }

        [OnDeserialized]
        private void SetValuesOnDeserialized(StreamingContext context)
        {
            selectedMoveOptionChanged = null;
            enableAutoMoveChanged = null;
            if (checkInterval == 0) checkInterval = 30;

        }

        public object Clone()
        {
            return new Settings(this);
        }
    }
}
